package com.bdbit.ChargingStation.services;

import com.bdbit.ChargingStation.Enum.OrderStatus;
import com.bdbit.ChargingStation.dao.mapper.OrderEntityMapper;
import com.bdbit.ChargingStation.entity.OrderEntity;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 订单服务
 *
 * @author sheng
 */
@Service
@AllArgsConstructor(onConstructor = @__(@Autowired))
public class OrderService {
    @Autowired
    private OrderEntityMapper orderEntityMapper;


    /**
     * 根据订单ID获取，订单数据
     *
     * @param orderNo 订单号
     */
    public OrderEntity getOrderByOrderNo(String orderNo) {

        return orderEntityMapper.selectByOrderNo(orderNo);
    }
    /**
     * 获取所有进行中的订单
     */
    public List<OrderEntity> getActiveOrders() {
        return orderEntityMapper.selectByStatus(OrderStatus.CHARGING.getCode());
    }



    /**
     * 更新订单数据
     */
    public void updateOrder(OrderEntity orderEntity) {
        orderEntityMapper.updateByPrimaryKeySelective(orderEntity);
    }


    /**
     * 根据主键ID获取订单数据
     *
     * @param id 主键ID
     */
    public OrderEntity getOrderById(Long id) {
        return orderEntityMapper.selectByPrimaryKey(id.intValue());
    }
}
